package com.venus.common.action;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.venus.common.form.BaseForm;
import com.venus.model.PubUserVO;

public class BaseAction extends Action {

	protected final Log log = LogFactory.getLog(getClass());
	
	public void set2Session(HttpServletRequest request, String strName, Object obj){
		HttpSession session = request.getSession(true);
		session.setAttribute(strName, obj);
	}
	
	public void remove2Session(HttpServletRequest request, String strName){
		HttpSession session = request.getSession(true);
		session.removeAttribute(strName);
	}
	
	public PubUserVO getLoginUser(HttpServletRequest request){
		HttpSession session = request.getSession(true);
		return (PubUserVO)session.getAttribute("objLoginUser");
	}
	
	public ActionForward forwardAjax(String out, HttpServletResponse response){
		response.setCharacterEncoding("utf-8");
		try {
			response.getWriter().write(out);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
    }
	
	public void isMenu(ActionMapping mapping, HttpServletRequest request, BaseForm objForm){
		String strIsMenu = request.getParameter("isMenu");
		if("y".equals(strIsMenu)){
			objForm.reset(mapping, request);
		}
	}
}
